package test1231.test3;

public class Database implements JavaLanguage {
    private static String[][] data = new String[100][3];
    private static int nextId = 1;
    @Override
    public void setDb(String name, int age) {
        data[nextId - 1][0] = String.valueOf(nextId);
        data[nextId - 1][1] = name;
        data[nextId - 1][2] = String.valueOf(age);
        System.out.println("数据库：添加数据成功，ID=" + nextId);
        nextId++;
    }

    @Override
    public void changeDb(int id, String name, int age) {
        if (id < 1 || id >= nextId || data[id - 1][0] == null) {
            System.out.println("数据库：修改失败，ID=" + id + " 不存在");
            return;
        }
        data[id - 1][1] = name;
        data[id - 1][2] = String.valueOf(age);
        System.out.println("数据库：修改数据成功，ID=" + id);
    }

    @Override
    public void deleteDb(int id) {
        if (id < 1 || id >= nextId || data[id - 1][0] == null) {
            System.out.println("数据库：删除失败，ID=" + id + " 不存在");
            return;
        }
        data[id - 1][0] = null;
        data[id - 1][1] = null;
        data[id - 1][2] = null;
        System.out.println("数据库：删除数据成功，ID=" + id);
    }
}
